#ifndef SERVER_H_
#define SERVER_H_

#include "../ipc/Message.h"
#include "../ipc/Queue.h"
#include "../common/CommonFunctions.h"
#include "../common/Log.h"
#include "../common/SignalHandler.h"
#include "../common/SIGINT_Handler.h"
#include "User.h"
#include "GroupChat.h"

#include <vector>
#include <string.h>

using namespace std;

class Server
{
private:
	SIGINT_Handler sigint_handler;
	Queue<message>* serverQueue;
	vector<User*> clients;
	vector<GroupChat*> groups;
	Log log;
	bool is_debug;
	
	message ackMessage(int pid, int gpid, string txt);
	message receiveMessage();
	void sendMessage(message msg);
	message connectClient(int pid, string nick);
	message disconnectClient(int pid);
	message createGroupChat(int pid, string name);
	message joinGroupChat(int pid, string name);
	message leftGroupChat(int pid, int gpid);
	message talkGroupChat(int pid, int gpid, string text);
	message showActiveGroupsChat(int pid);
	message showPeopleInGroupChat(int pid, string gp);

	void eraseGroupChat(int gpid);
	User* getUser(int pid);
	GroupChat* getGroupChat(int gpid);
	void debug(string line);
public:
	Server();
	void run();
	virtual ~Server();
};


#endif /*SERVER_H_*/
